/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import database.DataEngine;
import utils.ConfigReaderSlave;
import utils.Debug;
import utils.Def;

/**
 *
 * @author daz
 */
public class Runner {

    private static String address;
    private static String port;
    private static String dbAdress;
    private static String dbPort;
    private static String dbUser;
    private static String dbPass;
    private static String dbSchema;
    private static String logFilePath;

    public static void main(String[] args) {
        loadConfig();
        connectDatabase();
        startThread();
    }

    public static void loadConfig() {
        ConfigReaderSlave configReaderSlave = new ConfigReaderSlave();
        address = configReaderSlave.getValue(Def.STR_SLAVE_IPADDR);
        port = configReaderSlave.getValue(Def.STR_SLAVE_PORT);
        dbAdress = configReaderSlave.getValue(Def.STR_DB_IPADDR);
        dbPort = configReaderSlave.getValue(Def.STR_DB_PORT);
        dbUser = configReaderSlave.getValue(Def.STR_DB_USERNAME);
        dbPass = configReaderSlave.getValue(Def.STR_DB_PASSWORD);
        dbSchema = configReaderSlave.getValue(Def.STR_DB_SID);
        logFilePath = configReaderSlave.getValue(Def.LOGFILE_LOCATION);
    }

    public static void connectDatabase() {
        DataEngine dataEngine = DataEngine.getInstance();
        Debug.d("pass :" + dbPass);
        dataEngine.setConfig(dbAdress, Integer.parseInt(dbPort), dbUser, dbPass, dbSchema, dbSchema);
        dataEngine.connectToDabatabase();
    }

    private static void startThread() {
        ChargeThread chargeThread = new ChargeThread(address, port);
        chargeThread.start();
        chargeThread.setLogFilePath(logFilePath);
    }
}
